using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.XLANGs.BaseTypes;

namespace MapTestFramework.Common
{
    /// <summary>
    /// Represents a fixture class that contains test cases for testing BizTalk maps.
    /// </summary>
    public abstract class MappingFixture
    {
        #region Constructor And Initializing Members

        /// <summary>
        /// Default constructor.
        /// </summary>
        protected MappingFixture()
        {
            return;
        }

        #endregion

        #region Protected Members

        /// <summary>
        /// Returns the path to the base input file used as a base for all generated input files by the tests.
        /// </summary>
        protected abstract string SourcePathBase
        {
            get;
        }
        /// <summary>
        /// Returns the path to the base expected file used as a base for all generated expected files by the tests.
        /// </summary>
        protected abstract string ExpectedPathBase
        {
            get;
        }

        protected abstract IMapExecuter CreateMap();

        /// <summary>
        /// Executes the test that maps the base source file into the base expected file.
        /// </summary>
        protected void ExecuteBaseTest()
        {
            TestHelper helper = new 
                TestHelper(this.CreateMap(), SourcePathBase, ExpectedPathBase);
            helper.TestExecuted += new EventHandler<TestEventArgs>(HandleTestExecuted);
            helper.TestExecuting += new EventHandler<TestEventArgs>(HandleTestExecuting);
            helper.TestMap(TestHelper.GetTestMethodName());
            return;
        }
        /// <summary>
        /// Executes the specified test cases for a map.
        /// </summary>
        /// <param name="collection">Collection containing the test cases.</param>
        protected void ExecuteMapTest(MapTestCases collection)
        {
            TestHelper helper = new
                TestHelper(this.CreateMap(), SourcePathBase, ExpectedPathBase);
            helper.TestExecuted += new EventHandler<TestEventArgs>(HandleTestExecuted);
            helper.TestExecuting += new EventHandler<TestEventArgs>(HandleTestExecuting);
            helper.TestMap(TestHelper.GetTestMethodName(), collection);
            return;
        }
        /// <summary>
        /// Performs additional file manipulations before executing the test.
        /// </summary>
        /// <param name="sender">Object firing the event.</param>
        /// <param name="e">Meta data of the current test.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
        protected virtual void OnTestExecuting(object sender, TestEventArgs e)
        {
            return;
        }
        /// <summary>
        /// Performs additional file manipulations after the test has been executed.
        /// </summary>
        /// <param name="sender">Object firing the event.</param>
        /// <param name="e">Meta data of the current test.</param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
        protected virtual void OnTestExecuted(object sender, TestEventArgs e)
        {
            return;
        }

        #endregion

        #region Event Handlers

        private void HandleTestExecuting(object sender, TestEventArgs e)
        {
            OnTestExecuting(this, e);
            return;
        }
        private void HandleTestExecuted(object sender, TestEventArgs e)
        {
            OnTestExecuted(this, e);
            return;
        }

        #endregion
    }
}
